package d01014;
import java.util.Scanner;
public class ClearMineGame {
    private MineMap map;//扫雷地图
    private int pointsCount;//棋子的数量
    private Point[][]points;//地雷的布局 二维数组表示
    private Scanner sc = new Scanner(System.in);

    public void startGame(){
        int choice=0;
        System.out.println("**********欢迎进入扫雷游戏社区**************");
        System.out.println("请选择游戏等级：1.简单2.困难3.魔鬼");
        do {
            choice=sc.nextInt();
            switch(choice){
                case 1:
                   map = new MineMap(9,9,20);
                   break;
                case 2:
                    map = new MineMap(16,16,40);
                    break;
                case 3:
                    map = new MineMap(16,30,100);
                    break;
                default:
                    System.out.println("牧羊此选项，请重新选择：");
                    break;
            }
        }while(choice<1||choice>3);
        points = map.getMineMap();
        print();
        System.out.println("**************************");

        playGame();


    }
    //开始游戏
    public void playGame(){
        boolean isOver = false;
        showbord();
        int choice = 0;
        do {
            System.out.println("请输入下标（范围：1-9）（输入格式：0 0）：");
            int x = sc.nextInt();
            int y = sc.nextInt();
            Point point = points[x-1][y-1];
            System.out.println("请输入你的选项：1.打开2.插旗3.拔旗");
            choice = sc.nextInt();
            switch(choice){
                case 1:
                    isOver = openpoint(point);
                    break;
                case 2:insertFlag(point);break;
                case 3:delFlag(point);break;
                default:
                    System.out.println("没有此操作，请重新选择：");
                    break;
            }
        }while(choice<1 ||choice>3);
        if(isOver==true){
            showbord();
            System.out.println("游戏结束........");
        }else{
            playGame();
        }

    }
    //开始玩游戏
    public void insertFlag(Point point){

    }

    public void delFlag(Point point){

    }

    public boolean openpoint(Point point){
        return false;
    }

    private void openWhitePoint(Point point ){

    }
    //显示二维数组对象
    public void showbord(){
        //showCols();
       // showXin();
        for (int i=0;i<points.length;i++){
            System.out.println((i+1)+"*\t");
            for(int j=0;j<points[i].length;j++){
                if ( (points[i][j].getState()&0b110 )==0b0 ){
                    System.out.println("N\t");
                }else if( (points[i][j].getState()&0b110)==0b100 ){
                    System.out.println("F\t");
                }else {
                    if ( (points[i][j].getState()&0b1)==0b1 ){
                        System.out.println("M\t");
                    }else{
                        if ( (points[i][j].getState()>>3)==0 ){
                            System.out.println("\t");
                        }else{
                            System.out.println( (points[i][j].getState()>>3)+"\t" );
                        }
                    }
                }
            }
            System.out.println("*"+(i+1));
            System.out.println();
        }
        //showXin();
        //showCols();
    }

    private void print(){
        //showCol();
        //showXin();

    }
}

